package com.soecode.wxtools.util.http;

import com.soecode.wxtools.exception.WxErrorException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;

import java.io.IOException;
import java.util.Map;

public class SimpleGetRequestExecutor implements RequestExecutor<String, Map<String, String>> {
    @Override
    public String execute(CloseableHttpClient httpclient, String uri, Map<String, String> params)
            throws WxErrorException, IOException {
        if (params != null) {
            uri += '?';
            for (String key : params.keySet()) {
                uri += key + "=" + params.get(key) + "&";
            }
            uri = uri.substring(0, uri.length() - 1);
        }
        HttpGet httpGet = new HttpGet(uri);

        return validate(httpclient, httpGet);
    }

}
